package one.stand.task;

import com.jmp.base.dto.SmsCodeEnums;
import com.jmp.base.dto.SmsSendRequest;
import com.jmp.feign.SmsFeign;
import lombok.extern.slf4j.Slf4j;
import one.stand.mapper.UserApiAdminMapper;
import one.stand.service.MessageMsgService;
import one.stand.util.SqlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

//@Component
@Slf4j
public class UnReadMessageTask {
    @Autowired
    private MessageMsgService messageMsgService;
    @Autowired
    private UserApiAdminMapper userApiAdminMapper;
    @Autowired
    private SmsFeign smsFeign;

    @Scheduled(cron = "0 */30 * * * ?")
    public void unReadNotfiy() {
        log.debug("unread notify start");
        //获取未读消息 且 未发送通知
        List<String> targetIds = messageMsgService.getUnreadNotify();
//        List<String> targetIds = Lists.newArrayList("937");
        String ids = SqlUtil.in(targetIds);
        List<String> phones = userApiAdminMapper.selectPhoneList(ids);
        //发送通知
        SmsSendRequest request = SmsSendRequest.builder()
                .phones(phones)
                .type(SmsCodeEnums.unread_msg.getCode())
                .build();
        smsFeign.sendBatchSms(request);
    }
}
